package com.lzh.others.ComparableInterfacePrac;

import org.jetbrains.annotations.NotNull;

/**
 * @Description: @SuppressWarnings
 * 作用：告诉编译器忽略指定的警告，不用在编译完成后出现警告信息，提高开发效率
 * J2SE 5.0中标准的Annotation之一，可以标注在类，字段，方法，参数，构造方法，以及局部变量上
 * eg:
 * @SuppressWarnings(“unchecked”) : 忽略 unchecked 警告信息，如使用List，ArrayList等未进行参数化产生的警告信息。
 * @SuppressWarnings(“serial”) : 如果编译器出现这样的警告信息：The serializable class WmailCalendar does not declare a static final serialVersionUID field of type long，使用这个注释将警告信息去掉。
 * @SuppressWarnings(“deprecation”) : 如果使用了使用@Deprecated注释的方法，编译器将出现警告信息。使用这个注释将警告信息去掉。
 * @SuppressWarnings(“unchecked”, “deprecation”) : 告诉编译器同时忽略unchecked和deprecation的警告信息。
 * @SuppressWarnings(value={“unchecked”, “deprecation”}) 等同于@SuppressWarnings(“unchecked”, “deprecation”)
 * @Author: LiuZiHao
 * @Date: 2022/7/15 10:10
 */
@SuppressWarnings("rawtypes")
public class Student implements Comparable<Student> {

    private String name;
    private Double mathScore;
    private Double languageScore;
    private Double englishScore;
    private Double totalScore;
    private Integer age;

    public Student() {
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Student(String name, Double mathScore, Double languageScore, Double englishScore, Double totalScore, Integer age) {
        this.name = name;
        this.mathScore = mathScore;
        this.languageScore = languageScore;
        this.englishScore = englishScore;
        this.totalScore = totalScore;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getMathScore() {
        return mathScore;
    }

    public void setMathScore(Double mathScore) {
        this.mathScore = mathScore;
    }

    public Double getLanguageScore() {
        return languageScore;
    }

    public void setLanguageScore(Double languageScore) {
        this.languageScore = languageScore;
    }

    public Double getEnglishScore() {
        return englishScore;
    }

    public void setEnglishScore(Double englishScore) {
        this.englishScore = englishScore;
    }

    public Double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Double totalScore) {
        this.totalScore = totalScore;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", mathScore=" + mathScore +
                ", languageScore=" + languageScore +
                ", englishScore=" + englishScore +
                ", totalScore=" + totalScore +
                ", age=" + age +
                '}';
    }

    /**
     * Comparable<T>接口中的compareTo
     * 该方法内必须做非空判断(规范),int类型不用
     * 模型必须实现Comparable<T>接口
     * Collection.sort(list)会自动调用compareTo，如果没有这句，list是不会排序的，也不会调用compareTo方法
     * 如果是数组则用Arrays.sort方法
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(@NotNull Student o) {
        //按照 总分-数学-语文-英语(分数) 排序
        double result = this.totalScore - o.totalScore;
        if (result == 0) {
            result = this.mathScore - o.mathScore;
        }
        if (result == 0) {
            result = this.languageScore - o.languageScore;
        }
        if (result == 0) {
            result = this.englishScore = o.englishScore;
        }
        return (int) result;
    }

}
